package com.tool.emulator.apple2;

/**
 * Util.java @author tl 2011-6-19
 */
public class Util extends com.tool.emulator.common.Util {
	public static final int[] TEXT_ADDRS = new int[Apple2.TEXT_ROWS];
	public static final int[] HGR_ADDRS = new int[Apple2.SCREEN_HEIGHT];

	static {
		for (int row = 0; row < Apple2.TEXT_ROWS; row++)
			TEXT_ADDRS[row] = (row % 8) * 128 + (row / 8) * 40;

		for (int row = 0; row < Apple2.SCREEN_HEIGHT; row++)
			HGR_ADDRS[row] = (row % 8) * 8 * 128 + (row / 8 % 8) * 128 + (row / 8 / 8) * 40;
	}

	//helper functions
	public static int getTextAddr(boolean page2, int row) {
		return TEXT_ADDRS[row] + (page2 ? Apple2.ADDR_TEXT2 : Apple2.ADDR_TEXT1);
	}

	public static int getTextAddr(int row) {
		return getTextAddr(false, row);
	}

	public static int getHGRAddr(boolean page2, int row) {
		return HGR_ADDRS[row] + (page2 ? Apple2.ADDR_HGR2 : Apple2.ADDR_HGR1);
	}

}
